package test.presenter;

import javax.swing.JOptionPane;

import test.model.DefaultModel;
import ms.aurora.databinding.ModelObserver;
import ms.aurora.mvp.AbstractPresenter;
import ms.aurora.mvp.AbstractView;

import com.google.inject.Inject;

public class DefaultPresenter extends
		AbstractPresenter<DefaultPresenter.MyView> implements DefaultCallback,
		ModelObserver {
	@Inject
	private DefaultModel defaultModel;

	@Inject
	public DefaultPresenter(MyView view) {
		super(view);
	}

	public interface MyView extends AbstractView {

		public void setHelloLabelText(String text);

	}

	@Override
	public void onCloseButton() {
		String newName = JOptionPane.showInputDialog("Name:");
		defaultModel.bindTo(this);
		defaultModel.setName(newName);		
	}

	@Override
	public void onModelChanged(String valueName, Object value) {
		if (valueName.equals("name")) {
			getView().setHelloLabelText("Hello " + (String) value);
		}
	}
}
